package com.ganlebao.study.springcloudfeignclient.basic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.function.Supplier;

/**
 * 包裹feign的错误
 */
@Component
public class ExceptionFeignClient {
    public static final Logger logger = LoggerFactory.getLogger(ExceptionFeignClient.class);

    public <T> Optional<T> query(Supplier<T> supplier) {
        try {
            return Optional.of(supplier.get());
        } catch (Exception ex) {
            logger.error("执行方法[" + supplier.getClass() + "]异常", ex);
            return Optional.empty();
        }
    }
}
